package com.wlyuan.open.scanner.domain.message;

import lombok.var;

/**
 * @author lijing
 * @description
 */
public class MessageDataParse {

    /**
     * 解析数据
     *
     * @param tableNme
     * @param envelope
     * @return
     */
    public static MessageData parse(String tableNme, MessageEnvelope envelope) {
        var op = envelope.getOp();
        //创建 / 修改
        if (OperationTypeEnum.isCreate(op)) {
            return new MessageData(tableNme, envelope.getAfter());
        }
        //修改
        if (OperationTypeEnum.isUpdate(op)) {
            return new MessageData(tableNme, envelope.getAfter(), envelope.getBefore());
        }
        //删除
        if (OperationTypeEnum.isDelete(op)) {
            return new MessageData(tableNme, envelope.getBefore(), envelope.getBefore());
        }
        return null;
    }
}
